<template>
	<div class="login-container">
		<div class="login-box">
			<h1 class="title">用户登录</h1>
			<el-form :model="loginForm" :rules="rules" ref="formRef" label-width="60px" class="form">
				<el-form-item label="账号" prop="username">
					<el-input v-model="loginForm.username" placeholder="请输入账号"></el-input>
				</el-form-item>
				<el-form-item label="密码" prop="password">
					<el-input v-model="loginForm.password" type="password" placeholder="请输入密码"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="handleLogin" class="login-button">登录</el-button>
				</el-form-item>
			</el-form>
		</div>
	</div>
</template>

<script setup lang="ts">
import { ElForm } from 'element-plus';
import { useRouter } from 'vue-router';
const router = useRouter();

const formRef = ref<InstanceType<typeof ElForm>>();
const loginForm = ref({
	username: '',
	password: ''
});

const rules = ref({
	username: [
		{ required: true, message: '请输入账号', trigger: 'blur' }
	],
	password: [
		{ required: true, message: '请输入密码', trigger: 'blur' }
	]
});

const handleLogin = async () => {
	const res = await formRef.value?.validate();
	if (res) {
		// 登录逻辑
		router.push('/home');
		localStorage.setItem('token', '123456');
	}
};
</script>

<style scoped lang="scss">
.login-container {
	display: flex;
	justify-content: center;
	align-items: center;
	height: 100vh;
	background-color: #f0f2f5;
}

.login-box {
	background-color: #fff;
	padding: 40px;
	border-radius: 8px;
	box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
	width: 400px;
}

.title {
	font-size: 24px;
	font-weight: bold;
	text-align: center;
	margin-bottom: 20px;
	color: #333;
}

.form {
	margin-top: 20px;
}

.login-button {
	width: 100%;
}
</style>
